package com.itheima.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.Member;
import com.itheima.pojo.PhysiqueAssessment;
import com.itheima.service.MemberService;
import com.itheima.service.PhysiqueAssessmentService;
import com.itheima.utils.CookiesUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;


/**
 * @author ZS
 */

@RestController
@RequestMapping("physiqueAssessment")
public class PhysiqueAssessmentController {

    @Reference(version = "1.0.0")
    private PhysiqueAssessmentService physiqueAssessmentService;
    @Reference(version = "1.0.0")
    private MemberService memberService;

    /**
     * 根据ID查询报告 报告就是分数
     * @return  返回结果
     */

    @GetMapping("findPhysiqueAssessmentByPhoNumber")
//    @PreAuthorize("hasAuthority('CHECKGROUP_QUERY')")
    public Result findPhysiqueAssessmentByPhoNumber(HttpServletRequest request){
        String telephone = CookiesUtils.getCookie(request, "login_member_telephone");
        Member member = memberService.findByPhoneNumber(telephone);
        PhysiqueAssessment physiqueAssessment = physiqueAssessmentService.findByFileId( String.valueOf(member.getFileNumber()) );
        return new Result(true,"查询成功",physiqueAssessment);
    }


    /**
     * 删除
     * @param id 要删除的体质测评的ID
     * @return  编辑操作的结果
     */

    @GetMapping("delete/{id}")
//    @PreAuthorize("hasAuthority('CHECKGROUP_DELETE')")
    public Result delete(@PathVariable int id){
        //调用业务层删除方法
        physiqueAssessmentService.delete(id);
        //返回操作结果
        return new Result(true, "删除体质测评成功");
    }

/**
 * 分页查询方法
 * @param queryPageBean 分页参数实体类
 * @return  分页查询结果，总条数与当前页数据
 */

    @RequestMapping("findPage")
//    @PreAuthorize("hasAuthority('CHECKGROUP_QUERY')")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        PageResult pageResult = physiqueAssessmentService.findPage(
                queryPageBean.getCurrentPage(),
                queryPageBean.getPageSize(),
                queryPageBean.getQueryString());
        return pageResult;
    }
}
